package com.by.controller;

import com.by.bean.Corder;
import com.by.bean.Porder;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.service.CorderService;
import com.by.service.PorderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v1")
@Api(tags = "供应商订单管理")
public class PorderController extends BaseController {
    @Autowired
    PorderService porderService;
    @Autowired
    CorderService corderService;

    @ApiOperation("获取编号")
    @PostMapping("/porder/getcode")
    public ResultBean getpcode(){
        String pcode="P"+System.currentTimeMillis() ;
        return success("获取编号",pcode);
    }
    @ApiOperation("保存订单")
    @PostMapping("/porder/save")
    public ResultBean  save(@RequestBody Porder data){
        int rs =porderService.save(data);
        if (rs==1) {
                return success("成功");
        }else {
            return fail("失败");
        }
    }
    @ApiOperation("查询订单")
    @PostMapping("/porder/query")
    public ResultBean query(@RequestBody Porder order){
        List list=porderService.query(order);
        return success("查询",list);
    }
    @ApiOperation("更新状态")
    @PostMapping("/porder/updateStatus")
    public ResultBean updateStatus(@RequestBody Porder order){
        order.setStatus(order.getStatus()+1);
        int rs=porderService.pUpdateStatus(order);
        return  success("成功" ,rs);
    }

}
